<template>
  <a-modal
    :title="title"
    :width="500"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
     
	 <a-form-item
	         :labelCol="labelCol"
	         :wrapperCol="wrapperCol"
	         label="差异类型"
	         hasFeedback >
	 			   <a-select
	 					      v-model="differentTypeId"
	 					     style="width: 200px"
	 				class="
	 				input"
	 					    placeholder="请选择差异类型"
	 					  >
	 					     <a-select-option v-for="item in chayitypeList" :value="item.id.toString()"  :key="item.id" :label="item.different_types">
	 					          {{item.different_types}}
	 					          </a-select-option>
	 					</a-select>
	       </a-form-item>
		   
		   
  <a-form-item
    :labelCol="labelCol"
    :wrapperCol="wrapperCol"
    label="* 处理数量"
    hasFeedback >
    <a-input type="number" placeholder="请填写处理数量" v-decorator="['dealNumber', {}]" />
  </a-form-item>
  <a-form-item
    :labelCol="labelCol"
    :wrapperCol="wrapperCol"
    label="当前库存"
    hasFeedback >
    <a-input  v-model="newCount"  disabled="disabled"/>
  </a-form-item>
				
		
		<a-form-item
		      :labelCol="labelCol"
		      :wrapperCol="wrapperCol"
		      label="备注"
		      hasFeedback >
		     <a-textarea placeholder="请输入备注" v-decorator="['remark', {}]" rows="8" style="float: left;"/>
		    </a-form-item>
			
			
<a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <!-- <j-image-upload class="avatar-uploader" text="上传" v-model="fileList" style="margin-top: 8px;"></j-image-upload> -->
                  <!-- <el-upload
  style="margin-top: 20px;"
  action="http://clound_clothing.wenkangkeji.com/mlcc/user/interface/uploadImage"
  list-type="picture-card"
  :limit="1"
  :on-exceed="handleExceed"
  :on-preview="handlePictureCardPreview"
  :on-remove="handleRemove"
  :on-success="handleSuccess"
  ref="upload">
  <i class="el-icon-plus"></i>
</el-upload> -->
             上传凭证
            <j-image-upload class="avatar-uploader" text="上传" v-model="fileList" style="margin-top: 8px;"></j-image-upload>
       
                </a-form-item>
 
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction,getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
 import JImageUpload from '../../../components/jeecg/JImageUpload'
  export default {
    name: "addchayichuli",
     components: {
      JImageUpload
    },
    data () {
      return {
				goodsType:0,
		  id:'',
		  merchandiseInventoryId:'',
		  intoUnit:'',
		  differentTypeId:'',
		  chayitypeList:[],
		  newCount:"",
         fileList: [],
        goodsId:'',
        pingzheng:'',
        userId:'',
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: "/Chayi/addchayichuli",
          edit: "/Chayi/addchayichuli",
		  chayitypelist:"/Chayi/getAlldifferentType"
        },
      }
    },
    created () {
		this.getallchayitype();
    },
    methods: {
		
		//查询差异类型
		getallchayitype(){
			getAction(this.url.chayitypelist).then((res)=>{
			   if (res.success) {
			       this.chayitypeList=res.result;
			   this.xiangqingdetail.realname=realname;
			       } else {
			         that.$message.warning(res.message);
			       }
			     });
		},
		
       //上传图片成功函数
      handleSuccess(response, file, fileList) {
        var result = response;
        this.pingzheng = result.data;
      },
      add () {
        this.edit({});
      },
      edit (record) {
		    this.goodsType=record.goodsType;
		  
		    this.goodsId=record.goodsId;
		     this.merchandiseInventoryId=record.merchandiseInventoryId;
		  		    this.id=record.id;
		  
		  this.intoUnit=record.intoUnit;
        this.newCount=record.newCount;
        this.form.resetFields();
        // this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'name','keyWord','sex','age','email','content'))
		      //时间格式化
          this.form.setFieldsValue({punchTime:this.model.punchTime?moment(this.model.punchTime,'YYYY-MM-DD HH:mm:ss'):null})
          this.form.setFieldsValue({birthday:this.model.birthday?moment(this.model.birthday):null})
        });

      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
		  if( this.fileList==''){
		  							  this.$message.success("未上传图片 请选择");
		  							  return 0;
		  						 }
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);

            //时间格式化
            formData.punchTime = formData.punchTime?formData.punchTime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.birthday = formData.birthday?formData.birthday.format():null;
            formData['differentTypeId']=this.differentTypeId;
            formData['intoUnit']=this.intoUnit;
			  formData['goodsId']=this.goodsId;
			  formData['merchandiseInventoryId']=this.merchandiseInventoryId;
			  formData['remainingInventoryId']=this.id;
						  formData['goodsType']=this.goodsType;
			     
             formData['uploadDocuments']=this.fileList;
            console.log(formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('aaa');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>